package Triangulation;

import java.util.List;
import java.util.Vector;

import controller.Notification;
import controller.NotificationCenter;

import tools.SimpleLMTSkeletonCreator;
import Triangulation.minimalityMetrics.MinimalityMetric;
import Triangulation.oldMinimalityMetrics.OldMinimalityMetric;
import datatypes.Edge;
import datatypes.IndexedFaceSet;
import datatypes.Vertex;

/**
 * 
 * @author markessien, nils
 *
 */
public class SimpleLMTTriangulator implements LMTTriangulator
{
	SimpleLMTSkeletonCreator lmtSkeletonCreator;
	
	public SimpleLMTTriangulator (OldMinimalityMetric metric) {
		this.lmtSkeletonCreator = new SimpleLMTSkeletonCreator(metric);
	}
	
	@Override
	public List<Edge> processVertices(Vertex[] vertices, MinimalityMetric metric)
	{
		return processVertices(vertices, metric, false);
	}

	
	@Override
	public String getName()
	{
		return "Simple LMT: " + lmtSkeletonCreator.getMetricName();
	}

	@Override
	public List<Edge> processVertices(Vertex[] vertices,
			MinimalityMetric metric, boolean triangulatePolygons) {
		// Copy the points to a list
		IndexedFaceSet set = new IndexedFaceSet(false, false, vertices);
		
		// Calculate the LMT
		List<Edge> edgesArray = lmtSkeletonCreator.calculateLMT(set);
		
		// Copy the items back to a Vector
		Vector<Edge> edges = new Vector<Edge>(edgesArray.size());
		for (Edge edge : edgesArray) {
			edges.add(edge);
		}

		NotificationCenter nc = NotificationCenter.defaultNotificationCenter();
		nc.postNotification(Notification.didFinishMWT, edges);
		return edges;
	}
		
}